# https://gitee.com/yueyinqiu5990/tj12413601/blob/master/assignment1/question5/grating.py
class Grating:
    def __init__(
            self,
            ridge_width: float,
            period: float = 1,
            ridge_dielectric_coefficient: float = 5,
            groove_dielectric_coefficient: float = 1):
        self._period = period
        self._ridge_width = ridge_width
        self._ridge_dielectric_coefficient = ridge_dielectric_coefficient
        self._groove_dielectric_coefficient = groove_dielectric_coefficient

    def period(self):
        return self._period

    def ridge_width(self):
        return self._ridge_width

    def dielectric_coefficient(self, x: float):
        pd2 = self._period / 2
        x += pd2
        x %= self._period
        if x < self._ridge_width:
            return self._ridge_dielectric_coefficient
        else:
            return self._groove_dielectric_coefficient

    def ridge_dielectric_coefficient(self):
        return self._ridge_dielectric_coefficient

    def groove_dielectric_coefficient(self):
        return self._groove_dielectric_coefficient
